﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCToolkitWebExample.Models;
using MVCToolkit.Controls;
using MVCToolkit.Validations;

namespace MVCToolkitWebExample.Controllers
{
    public class InputController : Controller
    {
        //
        // GET: /Input/

        public ActionResult MVCPost()
        {
            InputModel inputModel = new InputModel();
            PopulateHobbyList(inputModel);

            return View(inputModel);
        }

        [HttpPost]
        public ActionResult MVCPost(InputModel inputModel)
        {
            if (this.ModelState.IsValid)
            {

            }

            return null;
        }

        public ActionResult KOPost()
        {
            InputModel inputModel = new InputModel();
            PopulateHobbyList(inputModel);

            return View(inputModel);
        }

        [HttpPost]
        public ActionResult KOPost(InputModel inputModel)
        {

            try
            {
                inputModel.FirstName = string.Empty;
                inputModel.Email = "email";
                inputModel.Validate();
            }
            catch (ValidationException validationException)
            {
                //Inspect validationException.ValidationResults for more details
            }

            return null;
        }

        private void PopulateHobbyList(InputModel inputModel)
        {
            IList<ListItem> hobbyList = new List<ListItem>();

            ListItem item1 = new ListItem() { Value = 1, Name = "Books" };
            ListItem item2 = new ListItem() { Value = 2, Name = "Movies", Selected = true };
            ListItem item3 = new ListItem() { Value = 3, Name = "Stamp Collection" };
            ListItem item4 = new ListItem() { Value = 4, Name = "Sports", Selected = true };
            ListItem item5 = new ListItem() { Value = 5, Name = "Trecking" };

            hobbyList.Add(item1);
            hobbyList.Add(item2);
            hobbyList.Add(item3);
            hobbyList.Add(item4);
            hobbyList.Add(item5);

            inputModel.HobbyOptions = hobbyList;
        }
    }
}
